﻿using Microsoft.AspNetCore.Mvc;
using System.Security.Cryptography;
using WebAPI.Common.Tools;
using WebAPI测试程序.Attr;
using WebAPI测试程序.IServices;

namespace WebAPI测试程序.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        //[Autowire]
        //public IUserService userService { get; set; }

        private IUserService userService;

        public UserController(IUserService userService) 
        { 
            this.userService = userService;
        }


        [HttpGet]
        public string Order(string? name,string? pwd)
        {
            userService.Login();
            return "用户下单完成";
        }

        [HttpGet]
        public string doSomething(string? name,int? age,string? gender)
        {
            string res = $"name: {name},age: {age},gender: {gender}";
            return res;
        }

        [HttpPost]
        public string getSomething([FromForm]string name, [FromForm]int age, [FromForm]string gender)
        {
            string res = $"name: {name},age: {age},gender: {gender}";
            return res;
        }

        // GET: api/<UserController>
        [HttpGet]
        public IEnumerable<string> Get()
        {
            Console.WriteLine(EncryptHelper.Md5Encrypt("helloworld"));
            userService.Info();
            return new string[] { "value1", "value2" };
        }

        // GET api/<UserController>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            userService.Debug();
            throw new Exception("抛出异常");
            return "value";
        }

        // POST api/<UserController>
        [HttpPost]
        public void Post([FromBody] string value)
        {
            userService.Warn();
        }

        // PUT api/<UserController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
            userService.Error();
        }

        // DELETE api/<UserController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
           
        }
    }
}
